home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / plot_3dbox.pro < prev    next >
Text File  |  1997-07-08  |  9KB  |  258 lines

  1. ;  $Id: plot_3dbox.pro,v 1.4 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1994-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;    Plot_3dbox
  8. ;
  9. ; PURPOSE:
  10. ;    This procedure plots data in a 3-dimensional box, with options
  11. ;    to have the data displayed on the walls surrounding the plot area.
  12. ;
  13. ; CATEGORY:
  14. ;    Plotting, Three-dimensional
  15. ;
  16. ; CALLING SEQUENCE:
  17. ;    Plot_3dbox, X, Y, Z
  18. ; INPUTS:
  19. ;    X:    A one dimensional array that contains the X coordinats
  20. ;
  21. ;    Y:    A one dimensional array that contains the Y coordinates
  22. ;
  23. ;    Z:    A one dimensional array that contains the Z coordinates
  24. ;
  25. ; OPTIONAL INPUTS:
  26. ;    None.
  27. ;    
  28. ; KEYWORD PARAMETERS:
  29. ;    COLOR:        The color for the Grid and Lines or the Color
  30. ;             for the box walls when the keyword SOLID_WALLS
  31. ;            is set.
  32. ;
  33. ;    BACKGROUND:    The background color of the plot or the color
  34. ;            of the Grid and Plot data when the SOLID_WALLS
  35. ;            keyword is set.
  36. ;
  37. ;    XY_PLANE:    Setting this keyword will cause the X and Y values
  38. ;            of the data to be plotted on the Z=0 axis plane.
  39. ;
  40. ;    XZ_PLANE:    Setting this keyword will cause the X and Z values
  41. ;            of the data to be plotted on the Y=Ymax axis plane.
  42. ;
  43. ;    YZ_PLANE:    Setting this keyword will cause the Y and Z values
  44. ;            of the data to be plotted on the X=Xmax axis plane.
  45. ;
  46. ;    SOLID_WALLS:    Setting this keyword causes the axis "walls" of 
  47. ;            the plot box to be filled with the value of COLOR.
  48. ;
  49. ;    PSYM:        The plotting symbol that the data is draw with.
  50. ;
  51. ;    GRIDSTYLE:    Set this keyword to the linestyle that will be 
  52. ;            used in drawing the gridlines.
  53. ;
  54. ;    TITLE:        Set this keyword to the Main plot title
  55. ;    
  56. ;    XTITLE:        Set this keyword to the X axis title.
  57. ;
  58. ;    YTITLE:        Set this keyword to the Y axis title.
  59. ;
  60. ;    ZTITLE:        Set this keyword to the Z axis title.
  61. ;
  62. ;     SUBTITLE:    Set this keyword to the Sub-Title 
  63. ;
  64. ;    LINESTYLE:    The linestyle used to plot the data.
  65. ;
  66. ;    XYSTYLE:    The linesytle used to draw the plot in the XY plane.
  67. ;            If this keyword is not set, the value of LINESTYLE
  68. ;            is used.
  69. ;
  70. ;    XZSTYLE:    The linesytle used to draw the plot in the XZ plane.
  71. ;            If this keyword is not set, the value of LINESTYLE
  72. ;            is used.
  73. ;
  74. ;    YZSTYLE:    The linesytle used to draw the plot in the YZ plane.
  75. ;            If this keyword is not set, the value of LINESTYLE
  76. ;            is used.
  77. ;
  78. ;    Surface         All other keywords available to SURFACE are also
  79. ;    Keywords:    used by this procedure.
  80. ;
  81. ; OUTPUTS:
  82. ;    None.
  83. ;
  84. ; OPTIONAL OUTPUTS:
  85. ;    None.
  86. ;
  87. ; COMMON BLOCKS:
  88. ;    None.
  89. ;
  90. ; SIDE EFFECTS:
  91. ;    Plotting on the current device is performed.
  92. ;
  93. ; RESTRICTIONS:
  94. ;    None.
  95. ;
  96. ; PROCEDURE:
  97. ;    Straightforward.  Unrecognized keywords are passed to the SURFACE
  98. ;    procedure.  
  99. ;
  100. ; EXAMPLE:
  101. ;       Create some data that can be passed to Plot_3dbox
  102. ;
  103. ;       x = Replicate(5., 10)
  104. ;       x1 = cos(findgen(36)*10.*!dtor)*2.+5.     
  105. ;       x=[x,x1,x]     
  106. ;       y = findgen(56)     
  107. ;       z = Replicate(5., 10)
  108. ;       z1 =sin(findgen(36)*10.*!dtor)*2.+5.     
  109. ;       z=[z,z1,z]     
  110. ;
  111. ;     ; Plot this data in a "plot box" 
  112. ;
  113. ;       Plot_3dbox, X, Y, Z, /XY_PLANE, /YZ_PLANE, /XZ_PLANE, $
  114. ;                 /SOLID_WALLS, GRIDSTYLE=1, XYSTYLE=3, XZSTYLE=4, $
  115. ;                 YZSTYLE=5, AZ=40, TITLE="Example Plot Box",      $
  116. ;                 Xtitle="X Coodinate", Ytitle="Y Coodinate",      $
  117. ;                 Ztitle="Z Coodinate", SubTitle="Sub Title",      $
  118. ;                 /YSTYLE, ZRANGE=[0,10], XRANGE=[0,10],Charsize=1.6
  119. ;
  120. ;     ; Then to plot symbols on the locations of the above plot
  121. ;
  122. ;       plots, X, Y, Z, /T3D, PSYM=4, COLOR=!p.background
  123. ;
  124. ; MODIFICATION HISTORY:
  125. ;       6/94   KDB, RSI   - Initial Coding and Testing
  126. ;
  127. ;-
  128.  
  129. PRO Plot_3dbox, X, Y, Z, COLOR=COLOR, BACKGROUND=BACKGROUND,        $  
  130.                     XY_PLANE=XY_PLANE, YZ_PLANE=YZ_PLANE,        $  
  131.                     XZ_PLANE=XZ_PLANE, SOLID_WALLS=SOLID_WALLS,  $  
  132.                     PSYM=PSYM, GRIDSTYLE=GRIDSTYLE, TITLE=TITLE, $
  133.             XTITLE=XTITLE, YTITLE=YTITLE, ZTITLE=ZTITLE, $
  134.             SUBTITLE=SUBTITLE, LINESTYLE=LINESTYLE,      $
  135.                     XYSTYLE=XYSTYLE, YZSTYLE=YZSTYLE, XZSTYLE=XZSTYLE, $
  136.                     _EXTRA=e       
  137.  
  138. ;  Set up simple error handling
  139.        
  140.    On_ERROR, 2
  141.  
  142. ;  Lets make sure that all arrays are the same size     
  143.        
  144.    Xcnt = N_Elements(X)      
  145.    Ycnt = N_Elements(Y)     
  146.    Zcnt = N_Elements(Z)     
  147.      
  148.    if (Xcnt ne Ycnt) or (Xcnt ne Zcnt) then $
  149.           Message, "X, Y and Z arrays must have same number of elements "      
  150.      
  151. ;  Check the values of the keywords  
  152.      
  153.    if(N_Elements(PSYM)  eq 0)then      PSYM = 0  
  154.    if(N_Elements(COLOR) eq 0)then      COLOR = !P.COLOR  
  155.    if(N_Elements(BACKGROUND) eq 0)then BACKGROUND = !P.BACKGROUND  
  156.    if(N_Elements(GRIDSTYLE) eq 0)then  GRIDSTYLE = 1  
  157.    if(N_Elements(LINESTYLE) eq 0)then  LINESTYLE = 0  
  158.    if(N_Elements(XYSTYLE) eq 0)then    XYSTYLE = LINESTYLE  
  159.    if(N_Elements(XZSTYLE) eq 0)then    XZSTYLE = LINESTYLE
  160.    if(N_Elements(YZSTYLE) eq 0)then    YZSTYLE = LINESTYLE
  161.  
  162.    if(not KeyWord_Set(TITLE))then      TITLE=''
  163.    if(not KeyWord_Set(SUBTITLE))then   SUBTITLE=''
  164.    if(not KeyWord_Set(XTITLE))then     XTITLE=''
  165.    if(not KeyWord_Set(YTITLE))then     YTITLE=''
  166.    if(not KeyWord_Set(ZTITLE))then     ZTITLE=''
  167.    if(not KeyWord_Set(ZRANGE))then     ZRANGE=[Min(Z, MAX=zmax), zmax]
  168.  
  169. ;  Use SURFACE to set up the coordinates system, handle titles ect...     
  170.      
  171.    Surface, FltArr(Xcnt,Xcnt), X, Y, /NODATA, /SAVE, TICKLEN=1,        $ 
  172.       COLOR=COLOR, XGRIDSTYLE=GRIDSTYLE, YGRIDSTYLE=GRIDSTYLE,         $ 
  173.       ZGRIDSTYLE=GRIDSTYLE, BACKGROUND=BACKGROUND, XTICK_GET=xt,       $ 
  174.       YTICK_GET=yt, ZTICK_GET=zt,ZRANGE=ZRANGE, SUBTITLE=SUBTITLE,     $
  175.       TITLE=TITLE, YTITLE=YTITLE, ZTITLE=ZTITLE, XTITLE=XTITLE, _EXTRA=e    
  176.  
  177.    name = replicate(' ' ,30)   ; Make up null tick names  
  178.      
  179. ;  See if the user wants to have "Solid" box walls  
  180.   
  181.    if(KeyWord_Set(SOLID_WALLS))then BEGIN  
  182.   
  183.    ;  Using the values of Crange, fill in the box walls with the value  
  184.    ;  of color  
  185.   
  186.       PolyFill, [!X.Crange[0], !X.Crange, !X.Crange[1]],  $;bottom  
  187.                 [!Y.Crange, !Y.Crange[1], !Y.Crange[0]],  $  
  188.                 Replicate(!Z.Crange[0], 4), /T3D, COLOR=COLOR  
  189.       PolyFill, [!X.Crange[0], !X.Crange, !X.Crange[1]],  $ ; Back  
  190.                 Replicate(!Y.Crange[1],4),                $  
  191.                 [!Z.Crange, !Z.Crange[1], !Z.Crange[0]],  $  
  192.                 /T3D, COLOR=COLOR  
  193.       PolyFill, Replicate(!X.Crange[1],4), /T3D, COLOR=COLOR, $ ;side  
  194.                 [!Y.Crange, !Y.Crange[1], !Y.Crange[0]],  $  
  195.                 [!Z.Crange[0], !Z.Crange, !Z.Crange[1]]  
  196.  
  197.    ;  Now Replot the surface data  
  198.   
  199.       COLOR=BACKGROUND  ; reverse colors 
  200.  
  201.       Surface, FltArr(Xcnt,Xcnt), X, Y, /NODATA, /SAVE, TICKLEN=1,       $ 
  202.               /NOERASE, COLOR=COLOR, XTICKNAME=name, YTICKNAME=name,     $  
  203.               ZTICKNAME=name, XGRIDSTYLE=GRIDSTYLE, YGRIDSTYLE=GRIDSTYLE,$  
  204.               ZGRIDSTYLE=GRIDSTYLE, ZRANGE=ZRANGE, _EXTRA=e     
  205.  
  206.    ENDif  ;if solid walls set.  
  207.    
  208. ;  Now complete the drawing of the axis box     
  209.      
  210.    Axis, !X.Crange[1], !Y.Crange[1], !Z.Crange[1], /YAXIS, /T3D,    $ 
  211.          YTICKNAME = name, COLOR=COLOR, YTICKLEN=0     
  212.    Axis, !X.Crange[1], !Y.Crange[0], !Z.Crange[0], ZAXIS=-1, /T3D,  $ 
  213.          ZTICKNAME = name, COLOR=COLOR, ZTICKLEN=0     
  214.    Axis, !X.Crange[0], !Y.Crange[1], !Z.Crange[0], /XAXIS, /T3D,    $ 
  215.          XTICKNAME = name, COLOR=COLOR, XTICKLEN=0     
  216.    Axis, !X.Crange[0], !Y.Crange[1], !Z.Crange[1], /XAXIS, /T3D,    $  
  217.          XTICKNAME = name, COLOR=COLOR, XTICKLEN=0     
  218.    Axis, !X.Crange[1], !Y.Crange[1], !Z.Crange[0], ZAXIS=-1, /T3D,  $ 
  219.          ZTICKNAME = name, COLOR=COLOR, ZTICKLEN=0     
  220.    Axis, !X.Crange[1], !Y.Crange[0], !Z.Crange[1], YAXIS=-1, /T3D,  $ 
  221.          YTICKNAME = name, COLOR=COLOR, YTICKLEN=0     
  222.    Axis, !X.Crange[1], !Y.Crange[0], !Z.Crange[0], /YAXIS, /T3D,    $ 
  223.          YTICKNAME = name, COLOR=COLOR, YTICKLEN=0     
  224.  
  225. ; now plot the data     
  226.      
  227.   Plots, X, Y, Z, /T3D , PSYM=PSYM, COLOR=COLOR ,LINESTYLE=LINESTYLE, $
  228.                          _EXTRA=e
  229.  
  230. ; And now plot the data along the walls of the box if requested
  231.  
  232.   if(KeyWord_Set(XY_PLANE))then $     
  233.       Plots, X, Y, Replicate(!Z.Crange[0], Zcnt), /T3D, COLOR=COLOR, $
  234.                LINESTYLE=XYSTYLE
  235.   if(KeyWord_Set(YZ_PLANE))then $     
  236.       Plots, Replicate(!X.Crange[1], Xcnt), Y, Z, /T3D, COLOR=COLOR, $
  237.                LINESTYLE=YZSTYLE
  238.   if(KeyWord_Set(XZ_PLANE))then $     
  239.       Plots, X, Replicate(!Y.Crange[1], Ycnt), Z, /T3D, COLOR=COLOR, $
  240.                LINESTYLE=XZSTYLE
  241.  
  242. ; now draw the grid lines on the plot that were not drawn by surface     
  243.      
  244.   for i=0, N_Elements(yt)-1 do $     
  245.         Plots, [!X.Crange[1],!X.Crange[1]], [yt[i],yt[i]], !Z.Crange, /T3D, $  
  246.                LINESTYLE=GRIDSTYLE, COLOR=COLOR  
  247.   for i=0, N_Elements(zt)-1 do $     
  248.         Plots, [!X.Crange[1],!X.Crange[1]], !Y.Crange, [zt[i],zt[i]], /T3D, $  
  249.                LINESTYLE=GRIDSTYLE, COLOR=COLOR  
  250.   for i=0, N_Elements(xt)-1 do $     
  251.         Plots, [xt[i],xt[i]], [!Y.Crange[1],!Y.Crange[1]], !Z.Crange, /T3D, $  
  252.                LINESTYLE=gridstyle, COLOR=COLOR  
  253.  
  254. END
  255.  
  256.  
  257.